import {ajax_user} from './ajax';
import {getCfg} from './skill';
import { getItem } from './storage';
import storage from '../config/storage.json';
import { BIGGIFTANIM } from './gift';

export function cfg(dispatch){
  ajax_user("cfg/initCfg")
  .then(responseJson => {
    dispatch({
      type: BIGGIFTANIM,
      list: responseJson.data.biggift
    });
  })
}

export function finish_userinfo(event){
    ajax_user("check/finsih_userinfo")
    .then(responseJson => {
      if(responseJson.result == 1){
          //填写个人资料
          if(responseJson.data.unfinish == 1){
            let appface = responseJson.data.appface;
            let nickname = responseJson.data.nickname;
            let birthday = responseJson.data.birthday;
            event.props.navigation.navigate('RegFillInfo', {
                appface: appface,
                nickname: nickname,
                birthday: birthday,
                transition: 'pop'
            });
          }else if(responseJson.data.unfinish == 2){
            getCfg((skillList) => {
              getItem([
                storage.userinfo.sex
              ]).then((result) => {
                  let sex = result[0][1];
                  event.props.navigation.navigate('RegFillFavor', {
                    sex: sex,
                    list: skillList,
                    transition: 'pop'
                  });
              })
            });
          }
      }
    })
}